/**
 * 
 */
package com.jszw.bcp.kernal.log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.jszw.bcp.demo.BaseController;
import com.jszw.bcp.kernal.common.InvokeResult;

/**
 * @author zhengzw
 *
 */
@Aspect
@Component
public class WebLogAspect {

	@Pointcut(value = "@within(com.jszw.bcp.kernal.log.WebLog)")
	public void logging() {

	}

	@Around(value = "logging()")
	public Object doLog(ProceedingJoinPoint point) throws Throwable {
		
		Class<?> clazz = point.getTarget().getClass();
		
		Logger logger = LoggerFactory.getLogger(clazz);
		
		if(clazz.getSuperclass() != BaseController.class) {
			throw new RuntimeException("类[" + clazz + "] 必须继承BaseController");
		}
		
		Object object = point.proceed();
		
		if(InvokeResult.class == object.getClass()) {
			logger.info("请求结果保存业务日志队列");
		}
		
		return object;
	}
}
